package com.mxw.component.security.configure;

import com.mxw.component.security.interceptor.ServerProtectInterceptor;
import com.mxw.component.security.properties.CloudSecurityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description TODO
 * @Author RingKo
 * @Date 2021/12/7 23:03
 * @Version 1.0
 */
public class CloudSecurityInterceptorConfigure implements WebMvcConfigurer {

  private CloudSecurityProperties properties;

  @Autowired
  public void setProperties(CloudSecurityProperties properties) {
    this.properties = properties;
  }

  public HandlerInterceptor serverProtectInterceptor() {
    ServerProtectInterceptor interceptor = new ServerProtectInterceptor();
    interceptor.setProperties(properties);
    return interceptor;
  }

  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(serverProtectInterceptor());
  }
}